{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Students Doing Homework at a Given Time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: busyStudent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #在既定时间做作业的学生人数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个整数数组 <code>startTime</code>（开始时间）和 <code>endTime</code>（结束时间），并指定一个整数 <code>queryTime</code> 作为查询时间。</p>\n",
    "\n",
    "<p>已知，第 <code>i</code> 名学生在 <code>startTime[i]</code> 时开始写作业并于 <code>endTime[i]</code> 时完成作业。</p>\n",
    "\n",
    "<p>请返回在查询时间 <code>queryTime</code> 时正在做作业的学生人数。形式上，返回能够使 <code>queryTime</code> 处于区间 <code>[startTime[i], endTime[i]]</code>（含）的学生人数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>startTime = [1,2,3], endTime = [3,2,7], queryTime = 4\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>一共有 3 名学生。\n",
    "第一名学生在时间 1 开始写作业，并于时间 3 完成作业，在时间 4 没有处于做作业的状态。\n",
    "第二名学生在时间 2 开始写作业，并于时间 2 完成作业，在时间 4 没有处于做作业的状态。\n",
    "第三名学生在时间 3 开始写作业，预计于时间 7 完成作业，这是是唯一一名在时间 4 时正在做作业的学生。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>startTime = [4], endTime = [4], queryTime = 4\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>在查询时间只有一名学生在做作业。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>startTime = [4], endTime = [4], queryTime = 5\n",
    "<strong>输出：</strong>0\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>startTime = [1,1,1,1], endTime = [1,3,2,4], queryTime = 7\n",
    "<strong>输出：</strong>0\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 5：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>startTime = [9,8,7,6,5,4,3,2,1], endTime = [10,10,10,10,10,10,10,10,10], queryTime = 5\n",
    "<strong>输出：</strong>5\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>startTime.length == endTime.length</code></li>\n",
    "\t<li><code>1 &lt;= startTime.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= startTime[i] &lt;= endTime[i] &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;=&nbsp;queryTime &lt;= 1000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-students-doing-homework-at-a-given-time](https://leetcode.cn/problems/number-of-students-doing-homework-at-a-given-time/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-students-doing-homework-at-a-given-time](https://leetcode.cn/problems/number-of-students-doing-homework-at-a-given-time/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3]\\n[3,2,7]\\n4', '[4]\\n[4]\\n4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans=0\n",
    "        for i in range(len(startTime)):\n",
    "            if queryTime<=endTime[i] and queryTime>=startTime[i]:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(map(lambda x,y: x <= queryTime <= y, startTime, endTime))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count = 0\n",
    "        for a,b in zip(startTime,endTime):\n",
    "            if a <= queryTime <= b:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count=0\n",
    "        for i in zip(startTime, endTime):\n",
    "            if i[0]<=queryTime and queryTime<=i[1]:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count=0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i]<=queryTime and endTime[i]>=queryTime:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        cnt = 0\n",
    "        num = len(startTime)\n",
    "        for i in range(num):\n",
    "            if queryTime >= startTime[i] and queryTime <= endTime[i]:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "\n",
    "        c=0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = len(startTime)\n",
    "        count = 0\n",
    "        for i in range(n):\n",
    "            if startTime[i] <= queryTime and queryTime <= endTime[i]:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i]<=queryTime<=endTime[i]:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum([s <= queryTime <= t for s, t in zip(startTime, endTime)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans=0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i]<=queryTime<=endTime[i]:\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i,j in zip(startTime,endTime):\n",
    "            if i<= queryTime and j >= queryTime:\n",
    "                ans +=1\n",
    "        return ans        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        account = 0\n",
    "        for i in range(0, len(startTime)):\n",
    "            if startTime[i] <= queryTime and endTime[i] >= queryTime:\n",
    "                account = account + 1\n",
    "        return account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = len(startTime)\n",
    "        count = 0\n",
    "        for i in range(n):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count = 0\n",
    "        for i,j in zip(startTime, endTime):\n",
    "            if i<=queryTime <=j:\n",
    "                count +=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return len([1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        i, cnt = 0, 0\n",
    "        while i <= (len(startTime) - 1):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                cnt += 1\n",
    "                i += 1\n",
    "            else:\n",
    "                i += 1\n",
    "        return cnt\n",
    "             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime:List[int], endTime:List[int], queryTime:int) -> int:\n",
    "        maxEndTime = max(endTime)\n",
    "        if queryTime > maxEndTime:\n",
    "            return 0\n",
    "        cnt = [0] * (maxEndTime + 2)\n",
    "        for s, e in zip(startTime, endTime):\n",
    "            cnt[s] += 1\n",
    "            cnt[e + 1] -= 1\n",
    "        return sum(cnt[:queryTime + 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if queryTime >= startTime[i] and queryTime <= endTime[i]:\n",
    "                res += 1\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime and endTime[i] >= queryTime :\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count=0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i]<=queryTime<=endTime[i]:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        a=0\n",
    "        for i in range(len(startTime)):\n",
    "            if queryTime>=startTime[i] and queryTime<=endTime[i]:\n",
    "                a+=1\n",
    "        return a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        if queryTime > max(endTime):return 0\n",
    "        if queryTime < min(startTime):return 0\n",
    "        ans = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if queryTime >= startTime[i] and queryTime <= endTime[i]:\n",
    "                ans +=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(endTime)):\n",
    "            if endTime[i] >= queryTime and startTime[i] <= queryTime:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res =  0\n",
    "        for start,end in zip(startTime,endTime):\n",
    "            if queryTime>= start and queryTime<=end:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n=len(startTime);cnt=0\n",
    "        for i in range(0,n):\n",
    "            if queryTime >= startTime[i] and queryTime <= endTime[i]:\n",
    "                cnt+=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = len(startTime)\n",
    "        res = 0\n",
    "        for i in range(n):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res = 0\n",
    "        time = [range(startTime[i],endTime[i]+1) for i in range(len(startTime))]\n",
    "        for i in time:\n",
    "            if queryTime in i:\n",
    "                res = res+1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum([1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        std_cnts = [0] * 1001\n",
    "        n = len(startTime)\n",
    "        for i in range(n):\n",
    "            for j in range(startTime[i], endTime[i] + 1):\n",
    "                std_cnts[j] += 1\n",
    "        return std_cnts[queryTime]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if queryTime in range(startTime[i] , endTime[i] + 1):\n",
    "                n += 1\n",
    "        return n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime and queryTime <= endTime[i]:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n=len(startTime)\n",
    "        count=0\n",
    "        for i in range(n):\n",
    "            if startTime[i]<=queryTime<=endTime[i]:\n",
    "                count+=1\n",
    "        return count\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for s, e in zip(startTime, endTime):\n",
    "            if queryTime <= e and queryTime >= s:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(endTime)):\n",
    "            if endTime[i] >= queryTime and startTime[i] <= queryTime:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        # max_time = max(endTime)\n",
    "        # if queryTime > max_time:\n",
    "        #     return 0\n",
    "        # student = [0] * (max_time+2)\n",
    "        # for s, e in zip(startTime, endTime):\n",
    "        #     student[s] += 1\n",
    "        #     student[e+1] -= 1\n",
    "        # return sum(student[:queryTime+1])\n",
    "\n",
    "        # -----------------------------------\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        l = len(startTime)\n",
    "        return sum(1 for i in range(l) if queryTime >= startTime[i] and queryTime <= endTime[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(0,len(startTime)):\n",
    "            if startTime[i] <= queryTime and endTime[i] >= queryTime:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime, endTime))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(s <= queryTime <= e for s, e in zip(startTime,endTime))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        stus = [0]*(max(endTime)+2)\n",
    "        for i in range(len(startTime)):\n",
    "            stus[startTime[i]]+=1\n",
    "            stus[endTime[i]+1]-=1\n",
    "        return sum(stus[:queryTime+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return len([1 for i in range(len(startTime)) if startTime[i] <= queryTime <= endTime[i]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for i in range(len(startTime)) if startTime[i]<=queryTime and endTime[i]>=queryTime)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for i, x in enumerate(startTime) if startTime[i] <= queryTime <= endTime[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return len(list(filter(lambda x: x[0] <= queryTime <= x[1], zip(startTime, endTime))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(1 for s, e in zip(startTime, endTime) if s <= queryTime <= e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return len([i for i in range(len(startTime)) if startTime[i]<= queryTime and endTime[i]>= queryTime])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum([i[0]<= queryTime and i[1] >= queryTime for i in zip(startTime,endTime)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ncount = 0\n",
    "        n = len(startTime)\n",
    "        for i in range(0,n):\n",
    "            if(startTime[i] <= queryTime and queryTime <= endTime[i]):\n",
    "                ncount += 1\n",
    "        return ncount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = len(startTime)\n",
    "        cnt = 0\n",
    "        for i in range(n):\n",
    "            if startTime[i] <= queryTime and endTime[i] >= queryTime:\n",
    "                cnt += 1\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans  = 0\n",
    "        for start, end in zip(startTime, endTime):\n",
    "            if start <= queryTime <= end:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        n = len(startTime)\n",
    "        cnt = 0\n",
    "        for i in range(n):\n",
    "            if endTime[i] >= queryTime and startTime[i] <= queryTime:\n",
    "                cnt += 1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        num = 0\n",
    "        for i, t in enumerate(startTime):\n",
    "            if t <= queryTime <= endTime[i]:\n",
    "                num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        result=0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i]<=queryTime<=endTime[i]:\n",
    "                result+=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        ans = 0\n",
    "        for i, start in enumerate(startTime):\n",
    "            if start <= queryTime <= endTime[i]:\n",
    "                ans += 1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        count = 0  # 初始化计数器为0，用于计数在 queryTime 时正在做作业的学生数量\n",
    "        for start, end in zip(startTime, endTime):\n",
    "            if start <= queryTime <= end:  # 如果 queryTime 在 [start, end] 区间内\n",
    "                count += 1  # 增加计数器\n",
    "        return count  # 返回结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        d = defaultdict(int)\n",
    "        for s, e in zip(startTime, endTime):\n",
    "            d[s] += 1\n",
    "            d[e + 1] -= 1\n",
    "        ans = 0\n",
    "        for i in range(queryTime + 1):\n",
    "            ans += d[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        return sum(start<=queryTime<=end for start, end in zip(startTime, endTime))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(startTime)):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int:\n",
    "        # 方法一：枚举\n",
    "        length = len(startTime)\n",
    "        count = 0\n",
    "        for i in range(length):\n",
    "            if startTime[i] <= queryTime <= endTime[i]:\n",
    "                count += 1\n",
    "            else:\n",
    "                continue\n",
    "        return count"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
